package com.nanbei.a01.component;

import com.nanbei.a01.event.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/9/4 16:03
 */
@Component
@Slf4j
public class Component2 {


    /**
     *  监听器
     * @param event 监听事件
     */
    @Async
    @EventListener(classes = {EmailEvent.class,PhoneEvent.class})
    public void listen(ApplicationEvent event){
        log.info("event:{}",event);
        if (event instanceof  EmailEvent){
            log.info(((EmailEvent) event).getMsg());
            log.info("发送邮件成功");
        }else if (event instanceof PhoneEvent){
            log.info(((PhoneEvent) event).getMsg());
            log.info("发送短信成功");
        }


    }
}
